package com.buba.system.pojo;

import com.buba.customer.pojo.Customer;
import com.buba.goods.pojo.MatterInfo;
import com.buba.goods.pojo.MatterPrice;
import lombok.Data;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

/**
 * 配置类
 */
@Data
public class Page implements Serializable {
    private List<MatterPrice> matterPricelist;
    private List<MatterInfo> matterInfoList;
    private List<Customer> customerList;
    private List<Menu> menuList;
    private List list;
    private Integer zxc;
    private String companyName;
    //当前页
    private Long  pageNow;
    //每页条数
    private Long  pageCount;
    // 总条数
    private Long pageTotal;
    //总条数
    private Long count;
    private Map<String,Object> map;
    // sql语句中的起始下标
    private Long  pageIndex;
    public Page(Integer pageNow) {
        this(pageNow, 5);
    }
    public Page() {
        this(1, 5);
    };
    public Page(long pageNow, long pageCount) {
        if (pageNow < 1)
            pageNow = 1;
        this.pageNow = pageNow;
        if (pageCount < 5)
            pageCount = 5;
        this.pageCount = pageCount;
        this.pageIndex = (pageNow - 1) * pageCount;
    }

    /**
     * 根据总条数计算总页数
     */
    public void computePageTotal(Long count) {
        this.count = count;
        // 计算总页数
        if (count % pageCount == 0)
            this.pageTotal = count / pageCount;
        else
            this.pageTotal = (count / pageCount) + 1;
        if (this.pageNow > this.pageTotal)
            this.pageNow = this.pageTotal;
    }
}
